package com.green.dao.impl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;

//读写打卡机数据
public class PunchCardAttendanceDBUtil {
	
	public static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
	
	public static DecimalFormat  nf = new DecimalFormat("00");
	public static DecimalFormat  nf2 = new DecimalFormat("#0.00");

	public static Connection getConnection() {
		String dbDriver = "net.sourceforge.jtds.jdbc.Driver";
		String strConnection = "jdbc:jtds:sqlserver://172.16.0.1:1433/smtkqxt";
		String user = "sa";
		String password = "";
		Connection conn = null;
		try {
			// 定义连接驱动
			Class.forName(dbDriver);
		} catch (java.lang.ClassNotFoundException e) {
			System.err.println("DBconnection():" + e.getMessage());
		}
		// --------连接SQL数据库------------------
		try {
			conn = DriverManager.getConnection(strConnection, user, password);
		} catch (SQLException ex) {
			System.err.println("aq.executeQuery:" + ex.getMessage());
		}
		return conn;
	}

	// -----------------------以下为关闭连接--------------------------
	public static void closeConnection(PreparedStatement ps, Connection conn,
			ResultSet rs) {
		try {
			if (rs != null) {
				rs.close();
			}
			if (ps != null) {
				ps.close();
			}
			if (conn != null) {
				conn.close();
			}
		} catch (SQLException sqlerror) {
			sqlerror.printStackTrace();
		}
	}

	public static void closeConnection(PreparedStatement ps, Connection conn) {
		try {
			if (ps != null) {
				ps.close();
			}
			if (conn != null) {
				conn.close();
			}
		} catch (SQLException sqlerror) {
			sqlerror.printStackTrace();
		}
	}

	public static void closeConnection(Connection conn) {
		try {
			if (conn != null) {
				conn.close();
			}
		} catch (SQLException sqlerror) {
			sqlerror.printStackTrace();
		}
	}
	
	
}
